package cn.itcast.bassm.util;

import java.io.File;
import java.util.List;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class AnalysisXML {
/*	public static void main(String[] args) throws Exception {
		// 通过IO获得Document
				SAXReader reader = new SAXReader();
				Document doc = reader.read(new File("E:\\桌面\\1201\\ssm\\src\\test.xml"));
				
				//得到根节点
				Element root=doc.getRootElement();
	}*/

	public static void parseXML() throws Exception{
		// 通过IO获得Document
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new File("E:\\桌面\\1201\\ssm\\src\\test.xml"));
		
		//得到根节点
		Element root=doc.getRootElement();
		
		//得到根
		List<Element>lementList=root.elements();
		
		//遍历
		for(Element e:lementList){
			System.out.println(e.getName()+"=>"+e.getTextTrim());
		}
	}
	
	public static void recursiveParseXML(Element root){
				//得到根节点的子节点列表
				List<Element>lementList=root.elements();
				//判断有没有子元素列表
				if(lementList.size()==0){
					System.out.println(root.getName()+"=>"+root.getTextTrim());
				}
				else {
					//遍历
					for(Element e:lementList){
						recursiveParseXML(e);
					}
					
				}
	}
}
